import { Image } from './apis/image/image';
import { Note } from './apis/note/note';
import { InjectionKey, App, inject } from 'vue';
import { Login } from './apis/login/login';
import { User } from './apis/user/user';
import { Comment } from './apis/comment/comment';

export class apiInstance {
  public readonly note = new Note();
  public readonly user = new User();
  public readonly login = new Login();
  public readonly image = new Image();
  public readonly comment = new Comment();
}

const key: InjectionKey<apiInstance> = Symbol();

export const installApi: (app: App, ...options: any[]) => any = app => {
  app.provide<apiInstance>(key, new apiInstance());
};

export const useApi = () => {
  return inject<apiInstance>(key) as apiInstance;
};
